package com.cloudkinto.utils;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import tiktokshop.open.sdk_java.api.ProductV202502Api;
import tiktokshop.open.sdk_java.invoke.ApiClient;
import tiktokshop.open.sdk_java.invoke.ApiException;
import tiktokshop.open.sdk_java.invoke.JSON;


public class CustomProductV202502Api extends ProductV202502Api {

    public CustomProductV202502Api(ApiClient apiClient) {
        super(apiClient);
    }
    public RequestBody serialize(Object obj, String contentType) throws ApiException {
   /*     if (obj instanceof byte[]) {
            // Binary (byte array) body parameter support.
            return RequestBody.create((byte[]) obj, MediaType.parse(contentType));
        } else if (obj instanceof File) {
            // File body parameter support.
            return RequestBody.create((File) obj, MediaType.parse(contentType));
        } else if ("text/plain".equals(contentType) && obj instanceof String) {
            return RequestBody.create((String) obj, MediaType.parse(contentType));
        } else*/ if (isJsonMime(contentType)) {
            String content;
            if (obj != null) {
                content = JSON.serialize(obj);
            } else {
                content = null;
            }
            return RequestBody.create(MediaType.parse(contentType), content);
        } else if (obj instanceof String) {
            return RequestBody.create(MediaType.parse(contentType), (String) obj);
        } else {
            throw new ApiException("Content type \"" + contentType + "\" is not supported");
        }
    }
    public boolean isJsonMime(String mime) {
        String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$";
        return mime != null && (mime.matches(jsonMime) || mime.equals("*/*"));
    }
}



